package com.ben.multiple.mail;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BenJin Yin
 * @date 2020/7/9
 */
@RestController
@RequestMapping
public class Rest {
    private final SendMailService sendMailService;

    public Rest(SendMailService sendMailService) {
        this.sendMailService = sendMailService;
    }

    @PostMapping("/send")
    public Boolean send(@RequestBody Map<String, String> body) {
        String to = body.get("to");
        String subject = "邮件发送测试";
        String text = "测试内容";
        return sendMailService.send(to, subject, text);
    }

    @PostMapping("/send/batch")
    public Boolean batchSend(@RequestBody Map<String, Object> body) {
        Object to = body.get("to");
        Set<String> collect = new HashSet<>((List) to);
        String subject = "邮件批量发送测试";
        String text = "测试内容";
        return sendMailService.batchSend(collect, subject, text);
    }
}
